#ifndef _FREFLOWEMB_H_
#define _FREFLOWEMB_H_

#ifndef _FPDFEMB_H_
#include "fpdfemb.h"
#endif

/**
 * @name Parser Flags
 */
/*@{*/
/** @brief Whether Parse image. */
#define RFEMB_PARSER_IMAGE		0x1 
/** @brief Whether slice image or text for page. */ 
#define RFEMB_PARSER_PAGEMODE	0x4 

#ifdef __cplusplus
extern "C" {
#endif

/** @brief Reflow page data structure. */
typedef void* RFEMB_ReflowedPage;

/**
 * Function: RFEMB_AllocReflowedPage
 *			Alloc a reflow page
 *
 * @return a Allocated page. NULL is out of memory.
 */
RFEMB_ReflowedPage RFEMB_AllocReflowedPage();

/**
 * Function: RFEMB_DestroyReflowedPage
 *			Destroy a reflow page
 *
 * @param[in] Page					Reflow page handle
 */
void RFEMB_DestroyReflowedPage(RFEMB_ReflowedPage Page);

/**
 * Function: RFEMB_GetRFPageSize
 *			Get the width and height of a reflowed page.
 *
 * @param[in] page					Page handle
 * @param[out] width				Page width
 * @param[out] height				Page height
 * @return Error code, or FPDFERR_SUCCESS for success.
 */
FPDFEMB_RESULT RFEMB_GetRFPageSize(RFEMB_ReflowedPage page, int* width, int* height);

/** @brief The pointer to reflow page object structure. */
typedef void* RFEMB_PageObjects;

/** @brief The pointer to reflow parser data structure. */
typedef void* RFEMB_Parser;

/**
 * Function: RFEMB_SetLineSpace
 *			 Set line space before parse page
 *
 * @param[in] page					Reflowed page handle.
 * @param[in] lineSpace				default value: 0
*/
FPDFEMB_RESULT RFEMB_SetLineSpace(RFEMB_ReflowedPage page, float lineSpace);

/**
 * Function: RFEMB_StartParse
 *			Start parsing a loaded PDF page into a reflowed page
 *
 * Comments:
 *			Page reflowing is a progressive process. It might take a long time to reflow
 *			a page. If "pause" parameter is provided, this function may return
 *			FPDFERR_TOBECONTINUED any time during reflowing.
 *
 *			When FPDFERR_TOBECONTINUED is returned, the reflowing is not finished. The
 *			application must call RFEMB_ContinueParse to continue reflowing.
 *
 * @param[in] page					A page handle returned by RFEMB_AllocReflowedPage function
 * @param[in] pdfPage				A PDF page handle
 * @param[in] width					The desired page width, in hundredth of points.
 * @param[in] fitPageHeight			The desired page height, in hundredth of points.
 * @param[in] pause					Pointer to a structure that can pause the rendering process.
 *									Can be NULL if no pausing is needed.
 *									If provided, this pointer has to be valid during the whole reflowing.
 * @param[in] flags					See RFEMB_PARSER_xxx flags defined above.
 *
 * @retval FPDFERR_SUCCESS			Page reflowed successfully.
 * @retval FPDFERR_ERROR			Internal error.
 * @retval FPDFERR_TOBECONTINUED	Reflowing paused by application.
 * @retval FPDFERR_PARAM			Parameter error.
 * @retval FPDFERR_MEMORY			Out of memory.
 */
FPDFEMB_RESULT RFEMB_StartParse(RFEMB_ReflowedPage page, FPDFEMB_PAGE pdfPage, 
 								  float width, float fitPageHeight, struct FPDFEMB_PAUSE* pause, int flags);

/**
 * @brief Function: RFEMB_ContinueParse
 *			Continue reflowing a PDF page
 *
 * @param[in] page					A handle returned by RFEMB_AllocReflowedPage function
 *
 * @retval FPDFERR_SUCCESS			Page successfully reflowed.
 * @retval FPDFERR_ERROR			Internal error.
 * @retval FPDFERR_TOBECONTINUED	Reflowing paused by application.
 * @retval FPDFERR_PARAM			Parameter error.
 * @retval FPDFERR_MEMORY			Out of memory.
 */
FPDFEMB_RESULT RFEMB_ContinueParse(RFEMB_ReflowedPage page);



/**
 * Function: RFEMB_SetDitherBits
 *			 Set dither bits for rendering
 *
 * @param[in] page					Reflowed page handle. The page has to be parsed first.
 * @param[in] DitherBits			default value: 2
*/
FPDFEMB_RESULT RFEMB_SetDitherBits(RFEMB_ReflowedPage page, int DitherBits);

/**
 * Function: RFEMB_StartRender
 *			Start rendering of a reflowed page.
 *
 * Comments:
 *			Rendering is a progressive process. This function starts the rendering process,
 *			and may return before rendering is finished, if a pause structure is provided.
 *
 *			Application should call RFEMB_ContinueRender repeatedly to finish the rendering 
 *			when return value is FPDFERR_TOBECONTINUED.
 *
 *			There can be only one rendering procedure for a page at any time. And rendering
 *			can be started over and over again for the same page. If a page rendering is already
 *			active, starting another one will cancel the previous rendering.
 *
 *			Rendering of a page doesn't draw the page background, therefore, you usually need
 *			to draw the background in the DIB yourself.
 *
 * @param[in] dib					DIB handle, as the rendering device
 * @param[in] page					Reflowed page handle. The page has to be parsed first.
 * @param[in] start_x				Left pixel position of the display area in the device coordination
 * @param[in] start_y				Top pixel position of the display area in the device coordination
 * @param[in] size_x				Horizontal size (in pixels) for displaying the page
 * @param[in] size_y				Vertical size (in pixels) for displaying the page
 * @param[in] rotate				Page orientation: 0 (normal), 1 (rotated 90 degrees clockwise),
 *									2 (rotated 180 degrees), 3 (rotated 90 degrees counter-clockwise).
 * @param[in] pause					Pointer to a structure that can pause the rendering process.
 * 									Can be NULL if no pausing is needed.
 *									If provided, this pointer has to be valid during the whole rendering.
 *
 * @retval FPDFERR_SUCCESS			Rendering successfully finished.
 * @retval FPDFERR_TOBECONTINUED	Rendering paused by application.
 * @retval FPDFERR_PARAM			Parameter error.
 * @retval FPDFERR_MEMORY			Out of memory.
 * @retval FPDFERR_ERROR			Internal error.
 */
FPDFEMB_RESULT RFEMB_StartRender(FPDFEMB_BITMAP dib, RFEMB_ReflowedPage page,
								 int start_x, int start_y, int size_x, int size_y, int rotate, struct FPDFEMB_PAUSE* pause);

/**
 * @brief Function: RFEMB_ContinueRender
 *			Continue rendering a reflowed page.
 *
 * @param[in] page					A handle returned by RFEMB_StartRender function
 *
 * @retval FPDFERR_SUCCESS			Document successfully loaded.
 * @retval FPDFERR_ERROR			Internal error.
 * @retval FPDFERR_TOBECONTINUED	Rendering paused by application.
 * @retval FPDFERR_PARAM			Parameter error.
 * @retval FPDFERR_MEMORY			Out of memory.
 */
FPDFEMB_RESULT RFEMB_ContinueRender(RFEMB_ReflowedPage page);

typedef void* RFEMB_Matrix;

/**
 * Function: RFEMB_AllocMatrix
 *			Allocate a matrix, NULL is out of memory.
 *
 * @param[in] page					Page handle. The page has to be parsed first.
 * @param[in] start_x				Left pixel position of the display area in the device coordination
 * @param[in] start_y				Top pixel position of the display area in the device coordination
 * @param[in] size_x				Horizontal size (in pixels) for displaying the page
 * @param[in] size_y				Vertical size (in pixels) for displaying the page
 * @param[in] rotate				Page orientation: 0 (normal), 1 (rotated 90 degrees clockwise),
 * @retval the matrix handle
*/
RFEMB_Matrix RFEMB_AllocMatrix(RFEMB_ReflowedPage page, int start_x, int start_y, int size_x, int size_y, int rotate);

/**
 * Function: RFEMB_AllocMatrix
 *			Destroy a matrix.
 * @param[in] matrix				Matrix handle. 
*/
void RFEMB_DestroyMatrix(RFEMB_Matrix matrix);

/**
 * Function: RFEMB_Focus_GetData
 *			Get data pointing to current reading position
 *
 * Comments:
 *			This function retrieves data pointing to given reading position.
 *			Application can convert it to the physical position by calling RFEMB_Focus_GetPosition.
 * @param[in] page					Handle to the page
 * @param[in] matrix				Handle to the matrix form RFEMB_AllocMatrix
 * @param[out] x					Destination x position
 * @param[out] y					Destination y position
 * @param[out] buffer				Application allocated buffer receiving the destination data
 *									If this parameter is NULL, then data won't be retrieved.
 * @param[in,out] bufsize			Pointer to an integer receiving data block size for the destination.
 * @retval FPDFERR_SUCCESS			Success.
 * @retval FPDFERR_PARAM			Parameter error.
 * @retval FPDFERR_MEMORY			Out of memory.
 * @retval FPDFERR_ERROR			Internal error.
 */
FPDFEMB_RESULT RFEMB_Focus_GetData(RFEMB_ReflowedPage page, RFEMB_Matrix matrix, int x, int y, void* buffer, int* bufsize);

/**
 * Function: RFEMB_Focus_GetPosition
 *			Get a pointing to current reading position
 *
 * Comments:
 *			This function Get an point from data retrieved from RFEMB_Focus_GetData.
 *
 * @param[in] page					Handle to the page
 * @param[in] matrix				Handle to the matrix form RFEMB_AllocMatrix
 * @param[in] data					Data form RFEMB_Focus_GetData
 * @param[in] size					Data size	
 * @param[out] x					Destination x position
 * @param[out] y					Destination y position
 * @retval FPDFERR_SUCCESS			Success.
 * @retval FPDFERR_PARAM			Parameter error.
 * @retval FPDFERR_MEMORY			Out of memory.
 * @retval FPDFERR_ERROR			Internal error.
 */
FPDFEMB_RESULT RFEMB_Focus_GetPosition(RFEMB_ReflowedPage page, RFEMB_Matrix matrix, 
										   void* data, int size, int* x, int* y);

#ifdef __cplusplus
};
#endif

#endif




 
